/*
 * This file is part of the GUI_SDK.
 *
 * Copyright (c) 2019-2019 Link-Card.Co.Ltd. All rights reserved.
 *
 * Authors:
 *    JiangYong <1556631285@qq.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * 'Software'), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * Function:  header file
 * Created on: 2019-10-05
 */

#ifndef  _event_h_
#define  _event_h_

#include "link_list.h"
#include "wifi.h"

#define OSD_WIDTH	1024
#define OSD_HEIGHT	768

typedef enum {
	//single short/long key
	KEY1_SHORT,
	KEY2_SHORT,
	KEY3_SHORT,
	KEY1_LONG,
	KEY2_LONG,
	KEY3_LONG,

	KEY1_5TIMES,
	KEY_TICK_300MS,

	//all
	KEY_NULL,
} eKeyVal;

#define NO_KEY	(-1)

enum {
	SETUP_normal,
	SETUP_search_wifi,
	SETUP_password,
	SETUP_ver_info,
	SETUP_basedevs,
};

enum {
	id_normal,
	id_search_wifi,
	id_password,
	id_ver_info,
	id_update,
	id_NULL,
};

enum {
	RUSSIAN,
	ENGLISH,
};

typedef struct {
	int  nid;
	int  min;
	int  max;
	int  val;
} snode_t;

typedef struct {
	snode_t wifi_signal_level;		// wifi信号强度
	snode_t wifi_status;			// 0：未连接WiFi，1：已经连接
	snode_t wifi_connect_status;	// 0：选择WiFi，1：选择连接或者忘记
	snode_t status_sel;
	snode_t wifi_password_sel;		// WiFi密码选择
	snode_t password_enter_num;		// 已经输入的密码个数
	snode_t wifi_index;				// 选择WiFi信号，max = WiFi信号个数
	snode_t wifi_page_index;
	snode_t enter_update;			// 1:可以选择是否升级
	snode_t language;
	snode_t lcd_brightness;
	struct sNode *list_head;
	snode_t wifi;
} devctx_t;

typedef struct {
    int osd_width;              // osd 分辨率
    int osd_height;
    int sensor_width;           // 探测器分辨率
    int sensor_height;
    int fpga_width;             // 机芯输出分辨率
    int fpga_height;
    int pip_width;              // pip 分辨率
    int pip_height;
    int pip_width_in_sensor;    // pip 在探测器坐标系下的分辨率
    int pip_height_in_sensor;
    int pip_change_pos;
} res_info_t;

typedef struct {
	char id[16];
	char sn[16];
	char gui_ver[8];
	char hw_ver[8];
	char sys_ver[16];
} ver_info_t;

typedef struct __GLOABLE_OBJECT__ {
	int curid;
	void *pgui;
	devctx_t devctx;
	res_info_t res_info;
	ver_info_t info;
} UICtx_t;

typedef struct __SETUP_FUNC__ {
	unsigned int id;
	unsigned keyval;
	int (*func_ptr)(void *p);
} SETUP_FUNC;

typedef struct __STATE_FUNC_ID__ {
	SETUP_FUNC  func_id[KEY_NULL+1];	
} STATE_FUNC_ID;

UICtx_t *getUICtx(void);
int Init_UICtx(UICtx_t *pobj, unsigned char mode);
int handle_event(UICtx_t * pobj, eKeyVal keyval);
unsigned int onExit();
int wifi_signal_level_switch(int signal_level);

#endif